package tony.com.test;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;

import tony.com.xframe.SMSBroadcastReceiver;


@SuppressLint("HandlerLeak")
public class SMSTestActivity extends Activity {
    SMSBroadcastReceiver.MessageCodeListener messageListener;
    //    private BroadcastReceiver smsReceiver;
    private IntentFilter filter2;

    private EditText et;

    tony.com.xframe.SMSBroadcastReceiver smsBroadcastReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et = (EditText) findViewById(R.id.et);
        filter2 = new IntentFilter();
        filter2.addAction("android.provider.Telephony.SMS_RECEIVED");
        filter2.setPriority(Integer.MAX_VALUE);
        messageListener = new SMSBroadcastReceiver.MessageCodeListener() {
            @Override
            public String getMessageCode(String code) {
                et.setText(code);


                return code;
            }
        };
        String fromCode = "15333611229";
        smsBroadcastReceiver = new SMSBroadcastReceiver(messageListener, fromCode, 4);
        registerReceiver(smsBroadcastReceiver, filter2);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(smsBroadcastReceiver);
    }


}
